﻿using Apps.Common;
using Apps.Models;
using System.Linq;
using System.Collections.Generic;
using Apps.Models.PUB;
using Apps.IBLL.PUB;
using Microsoft.Practices.Unity;

namespace Apps.BLL.PUB
{
    public partial class PUB_SUPPLIERTRANSPORTBLL
    {
        [Dependency]
        public IPUB_TRANSPORTBLL m_Mater { get; set; }

       
        public override List<PUB_SUPPLIERTRANSPORTModel> GetListByParentId(ref GridPager pager, string queryStr, object parentId)
        {
            IQueryable<PUB_SUPPLIERTRANSPORT> queryData = null;
            string pid = parentId.ToString();
            if (pid != "0")
            {
                queryData = m_Rep.GetList(a => a.SUPPLIER_ID == pid);
            }
            else
            {
                queryData = m_Rep.GetList();
            }
            if (!string.IsNullOrWhiteSpace(queryStr))
            {
                queryData = m_Rep.GetList(
                            a => (
                                    a.SUPPLIER_ID.Contains(queryStr)
                                   || a.TRANSPORT_ID.Contains(queryStr)
                                 )
                            );
            }
            pager.totalRows = queryData.Count();
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return CreateModelList(ref queryData);
        }
        public override List<PUB_SUPPLIERTRANSPORTModel> CreateModelList(ref IQueryable<PUB_SUPPLIERTRANSPORT> queryData)
        {

            List<PUB_SUPPLIERTRANSPORTModel> modelList = (from r in queryData
                                                         select new PUB_SUPPLIERTRANSPORTModel
                                                         {
                                                             SUPPLIER_ID = r.SUPPLIER_ID,
                                                             TRANSPORT_ID = r.TRANSPORT_ID,
                                                         }).ToList();
            return modelList;
        }
        public override PUB_SUPPLIERTRANSPORTModel GetById(object id)
        {
            if (IsExists(id))
            {

                PUB_SUPPLIERTRANSPORT entity = m_Rep.GetById(id);
                PUB_SUPPLIERTRANSPORTModel model = new PUB_SUPPLIERTRANSPORTModel();
                model.SUPPLIER_ID = entity.SUPPLIER_ID;
                model.TRANSPORT_ID = entity.TRANSPORT_ID;
                return model;
            }
            else
            {
                return null;
            }
        }
    }
}

